# @Time : 2020/7/18 17:18
# @Author : Fioman 
# @Phone : 13149920693
"""
在RGB色彩空间的三个通道的基础上,还可以加上一个A通道,也叫alpha通道,表示透明度.这种四个通道的色彩空间被称为RGBA色彩空间.
PNG图像是一种典型的4通道图像.alpha通道的赋值范围是[0,1],或者[0,255],表示从透明到不透明.
"""

import cv2 as cv
import numpy as np

img = np.random.randint(0,255,size=[2,3,3],dtype=np.uint8)
bgra = cv.cvtColor(img,cv.COLOR_BGR2BGRA)
print("img = \n",img)
print("bgra = \n",bgra)
b,g,r,a = cv.split(bgra)

print("a = \n",a)
a[:,:] = 125
bgra = cv.merge([b,g,r,a])
print("bgra = \n",bgra)

img = cv.imread("lenaColor.png",cv.IMREAD_COLOR)
bgra = cv.cvtColor(img,cv.COLOR_BGR2BGRA)
b,g,r,a = cv.split(bgra)
a[:,:] = 125
bgra125 = cv.merge([b,g,r,a])
a[:,:] = 0
bgra0 = cv.merge([b,g,r,a])

cv.imshow("img",img)
cv.imshow("bgra",bgra)
cv.imshow("bgra125",bgra125)
cv.imshow("bgra0",bgra0)
cv.waitKey(0)












